package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Product;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Bestsellers;
import com.ruoyi.system.service.IBestsellersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热销商品配置Controller
 * 
 * @author zhang
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/system/bestsellers")
public class BestsellersController extends BaseController
{
    @Autowired
    private IBestsellersService bestsellersService;

    /**
     * 查询热销商品配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bestsellers bestsellers)
    {
        startPage();
        List<Bestsellers> list = bestsellersService.selectBestsellersList(bestsellers);
        return getDataTable(list);
    }

    /**
     * 导出热销商品配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:export')")
    @Log(title = "热销商品配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bestsellers bestsellers)
    {
        List<Bestsellers> list = bestsellersService.selectBestsellersList(bestsellers);
        ExcelUtil<Bestsellers> util = new ExcelUtil<Bestsellers>(Bestsellers.class);
        util.exportExcel(response, list, "热销商品配置数据");
    }

    /**
     * 获取热销商品配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:query')")
    @GetMapping(value = "/{bestsellersId}")
    public AjaxResult getInfo(@PathVariable("bestsellersId") Long bestsellersId)
    {
        return success(bestsellersService.selectBestsellersByBestsellersId(bestsellersId));
    }

    /**
     * 新增热销商品配置
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:add')")
    @Log(title = "热销商品配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bestsellers bestsellers)
    {
        return toAjax(bestsellersService.insertBestsellers(bestsellers));
    }

    /**
     * 修改热销商品配置
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:edit')")
    @Log(title = "热销商品配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bestsellers bestsellers)
    {
        return toAjax(bestsellersService.updateBestsellers(bestsellers));
    }

    /**
     * 删除热销商品配置
     */
    @PreAuthorize("@ss.hasPermi('system:bestsellers:remove')")
    @Log(title = "热销商品配置", businessType = BusinessType.DELETE)
	   @DeleteMapping("/{bestsellersIds}")
    public AjaxResult remove(@PathVariable Long[] bestsellersIds)
    {
        return toAjax(bestsellersService.deleteBestsellersByBestsellersIds(bestsellersIds));
    }

    /**
     * 查询所有商品信息配置
     */
    @GetMapping("/products")
    public AjaxResult listProducts() {
        List<Product> list = bestsellersService.selectAllProducts();
        return success(list);
    }



}
